package Tree;

public class _98_ValidateBinarySearchTree {
    public boolean isValidBST(TreeNode root) {
        return helper(root, Long.MIN_VALUE, Long.MAX_VALUE);
    }

    public boolean helper(TreeNode root, long min, long max) {
        if(root==null) return true;
        return (min < root.val && root.val < max) && helper(root.left, min, Math.min(max, root.val))
                && helper(root.right, Math.max(root.val, min), max);
    }

}
